/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import path from 'path';

import { CommonConst } from '../const/common-const.js';

import { TaskNames } from './common/task-names.js';
import { TargetTaskService } from './service/target-task-service.js';
import Task = TaskNames.Task;
import { JsonProfile } from '../model/json-profile.js';
import { resModelLoader } from '../utils/loader/file/res-model-loader.js';

import { AbstractSyscapTransform } from './abstract/abstract-syscap-transform.js';

/**
 * Syscap Transform Task
 *
 * @since 2022/02/22
 */
export class SyscapTransform extends AbstractSyscapTransform {
  private readonly jsonFilePath: string;

  constructor(taskService: TargetTaskService) {
    super(taskService, Task.SYSCAP_TRANSFORM);
    this.jsonFilePath = path.resolve(this.sourceRoot, CommonConst.MODULE_JSON5);
  }

  protected getJsonProfileByModel(): JsonProfile {
    const jsonFile = resModelLoader.getModuleJson(this.jsonFilePath);
    return {
      jsonFilePath: this.jsonFilePath,
      profile: jsonFile,
      deviceTypes: jsonFile.module.deviceTypes,
      deviceConfig: CommonConst.DEVICE_TYPES,
      configurationProfile: CommonConst.MODULE_JSON5,
    };
  }
}
